<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/1/22
  Time: 16:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
    <title>Title</title>
    <script>

        /*
         WebRTC的另外两个API，RTCPeerConnection用于浏览器之间点对点的连接，RTCDataChannel用于点对点的数据通信。
         RTCPeerConnection带有浏览器前缀，Chrome浏览器中为webkitRTCPeerConnection，Firefox浏览器中为mozRTCPeerConnection。Google维护一个函数库adapter.js，用来抽像掉浏览器之间的差异。
         */
        var dataChannelOptions = {
            ordered: false, // do not guarantee order
            maxRetransmitTime: 3000, // in milliseconds
        };

        var peerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
        var SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription;
        var GET_USER_MEDIA = navigator.getUserMedia ? "getUserMedia" :
                navigator.mozGetUserMedia ? "mozGetUserMedia" :
                        navigator.webkitGetUserMedia ? "webkitGetUserMedia" : "getUserMedia";
        var v = document.createElement("video");
        var SRC_OBJECT = 'srcObject' in v ? "srcObject" :
                'mozSrcObject' in v ? "mozSrcObject" :
                        'webkitSrcObject' in v ? "webkitSrcObject" : "srcObject";

        // var peerConnection = new RTCPeerConnection();
        console.log(peerConnection);
        // Establish your peer connection using your signaling channel here
        var dataChannel =peerConnection.createDataChannel("myLabel", dataChannelOptions);

        dataChannel.onerror = function (error) {
            console.log("Data Channel Error:", error);
        };

        dataChannel.onmessage = function (event) {
            console.log("Got Data Channel Message:", event.data);
        };

        dataChannel.onopen = function () {
            dataChannel.send("Hello World!");
        };

        dataChannel.onclose = function () {
            console.log("The Data Channel is Closed");
        };

    </script>
</head>
<body>

</body>
</html>
